/**
 * Created by spatra on 14-9-8.
 */

define(function(){
	var quadraticEquations = function(a, b, c){
		var delta =  b * b - 4 * a * c ;
		var x1, x2;

		if( delta < 0 ){
			return null;
		}
		else if( delta == 0 ){
			x1 = x2 = -1 * b / (2 * a);
		}
		else{
			x1 = ( -1 * b + Math.sqrt(delta) ) / ( 2 * a );
			x2 = ( -1 * b - Math.sqrt(delta) ) / ( 2 * a );
		}

		return {
			x1: x1,
			x2: x2
		}

	};

	var formatFloat = function(floatNum, digit){
		var m = Math.pow(10, digit);
		return parseInt( floatNum * m, 10) / m;
	};

	var resolveDistanceByCoordinate = function(x1, y1, x2, y2){
		var dx = x1 - x2;
		var dy = y1 - y2;

		return Math.sqrt( Math.pow(dx, 2) + Math.pow(dy, 2) );
	};

	return {
		quadraticEquations: quadraticEquations,
		formatFloat: formatFloat,
		resolveDistanceByCoordinate: resolveDistanceByCoordinate
	};

});